<?php

namespace Event\Drive\Data\Cache;

class Cache
{
    /**
     * @var \Redis
     */
    private $redis;

    /**
     * @var string
     */
    private $cacheKey;


    public function __construct(string $cacheKey){
        $this->redis =  CacheConnect::getRedis();
        $this->cacheKey = $cacheKey;
    }

    /**
     * @param $eventClassName
     * @return false|int|\Redis
     * @throws \RedisException
     */
    public function getEvent($eventClassName)
    {
        return $this->redis->zrank($this->cacheKey, $eventClassName);
    }

    /**
     * @param $eventClassName
     * @param $status
     * @return false|int|\Redis
     * @throws \RedisException
     */
    public function setEvent($eventClassName, $status)
    {
        return $this->redis->zadd($this->cacheKey, $status, $eventClassName);
    }

    /**
     * @param string $eventClassName
     * @return false|int|\Redis
     * @throws \RedisException
     */
    public function delEvent(string $eventClassName)
    {
        $this->redis->multi();
        $this->redis->zrem($this->cacheKey, $eventClassName);
        $this->redis->watch($this->cacheKey);
        $this->redis->exec();
    }
}
